package com.isesol.api.example;

import com.isesol.api.rest.cgi.config.RestServiceConfiguration;
import com.isesol.api.rest.cgi.utils.RestServiceUtils;
import com.isesol.arch.common.utils.SpringContextHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author Peter Zhang
 */
@Controller
@RequestMapping(value = "/demo")
public class TestController {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @RequestMapping(value = "/init")
    public void init() {
        RestServiceConfiguration configuration = SpringContextHolder.getBean(RestServiceConfiguration.class);

        // 检查配置
        if (!configuration.checkConfig()) {
            logger.error("check rest config fail, please recheck!");
            System.exit(1);
        }

        if (!configuration.isInitServiceMappingLazy()) {
            logger.debug("+++++++++++  初始化服务配置-开始  +++++++++++");
            RestServiceUtils.registerServices(configuration);
            logger.debug("+++++++++++  初始化服务配置-完成  +++++++++++");
        }
    }

}
